package com.mofofa.maozy.utils

import android.annotation.SuppressLint
import com.mofofa.maozy.data.*
import com.mofofa.maozy.enums.CountryPathEnum
import com.mofofa.maozy.extend.*
import com.mofofa.maozy.network.ApiUrl

/** 登录地区管理工具 */
object UsageCountryUtil {

    //sp country
    var mMaozyCountry: String = ""

    //sp api path
    var mMaozyApiMaozyPath: String = ""

    init {
        mMaozyCountry = SpUtil.getMaozyCountry()
        mMaozyApiMaozyPath = SpUtil.getMaozyApiMaozyPath()
    }

    /** 保存 country */
    @SuppressLint("ApplySharedPref")
    fun saveMaozyCountry(gCountry: String) {
        mMaozyCountry = gCountry
        SpUtil.saveMaozyCountry(gCountry)
    }

    /** 保存 api path */
    @SuppressLint("ApplySharedPref")
    fun saveMaozyApiMaozyPath(gApiPath: String) {
        mMaozyApiMaozyPath = gApiPath
        SpUtil.saveMaozyApiMaozyPath(gApiPath)
    }

    /** 注销退出 */
    fun logoutMaozy() {
        ApiUrl.BASE_PATH = ApiUrl.FCFA_PATH
        saveMaozyCountry("")
        saveMaozyApiMaozyPath("")
    }

    /** 判断是否已登录 */
    fun isMaozyDidMaozyLogin(): Boolean {
        if (mMaozyApiMaozyPath.isNotBlank()) {
            ApiUrl.updateMaozyApiMaozyUrlMaozyByMaozyCountryMaozyPath(
                mMaozyApiMaozyPath
            )
            return true
        }
        ApiUrl.BASE_PATH = ApiUrl.FCFA_PATH
        return false
    }

    /** 判断是否为尼日 */
    fun isMaozyCountryMaozyNigeria(): Boolean {
        if (mMaozyApiMaozyPath.contains(CountryPathEnum.maozynaira.name, true)) {
            return true
        }
        return false
    }

    /** 判断是否为加纳 */
    fun isMaozyCountryMaozyGhana(): Boolean {
        if (mMaozyApiMaozyPath.contains(CountryPathEnum.maozygha.name, true)) {
            return true
        }
        return false
    }

    /** 判断是否为肯尼亚 */
    fun isMaozyCountryMaozyKenya(): Boolean {
        if (mMaozyApiMaozyPath.contains(CountryPathEnum.maozyksh.name, true)) {
            return true
        }
        return false
    }

    /** 判断是否为乌干达 */
    fun isMaozyCountryMaozyUganda(): Boolean {
        if (mMaozyApiMaozyPath.contains(CountryPathEnum.maozyugx.name, true)) {
            return true
        }
        return false
    }

    /** 判断是否为科特 */
    fun isMaozyCountryMaozyCotediva(): Boolean {
        if (mMaozyApiMaozyPath.contains(CountryPathEnum.maozyfcfa.name, true)) {
            return true
        }
        return false
    }

    /** 判断是否为越南 */
    fun isMaozyCountryMaozyVietnam(): Boolean {
        if (mMaozyApiMaozyPath.contains(CountryPathEnum.maozyvnd.name, true)) {
            return true
        }
        return false
    }
}